<?php
/**
 * 获取指定店铺的订单
 *
 * @author hzjsq@msn.com
 * @version 01.
 */
$argv [1] = 'gome.com';
$argv [2] = '2012-11-16 00:00:00';
$argv [3] = '2012-11-16 23:59:59';

$domain = $argv [1];
$sDate = time () - 86400; // strtotime($argv[2]);
$eDate = time (); // strtotime($argv[3]);

define ( 'COMMAND_MODE', true );

set_time_limit ( 0 );

define ( 'LIB_DIR', dirname ( __FILE__ ) . '/lib/' );
require_once (dirname ( __FILE__ ) . '/lib/init.php');
require_once (LIB_DIR . 'api/gome/order.php');


$orderObj = new tools_api_gome_order ();

 $sdf=$_POST['sdf'];
 $sdf =stripslashes($sdf);
 //$sdf = str_replace("\",'',$sdf);
 $order = json_decode($sdf,true);
 //var_dump($order);

 $fullInfo=$order['trade_fullinfo_get_response']['trade'];
 if (!empty($fullInfo)) {
 
 	if (isset($fullInfo['orders']['order']['adjust_fee'])) {
 
 		$fullInfo['orders']['order'] = array($fullInfo['orders']['order']);
 	}
 
 	$orderOme= $orderObj->transOrderDetail($fullInfo);
 }
 

 
//echo '666666666666666666666';
// echo strval($tid);

  //echo $sdf;
 //var_dump($orderOme);
// echo "{$tid} \n";
if (! empty ( $orderOme )) {
	$tid = $orderOme['order_bn'];
	if (insertIntoOrder ( $orderOme, '999999' )) {
		ob_start();//不加这个是不行的(貌似不加可以)
		//echo "不要显示";
		ob_end_clean();
		echo "{$tid} done.\n";
	
	} else {
		ob_start();//不加这个是不行的(貌似不加可以)
		//echo "不要显示";
		ob_end_clean();
		echo "{$tid} fail.\n";
	}
}

function insertIntoOrder($sdf, $nodeId) {
	
	static $orderObj = null;
	static $response = null;
	
	if (! $orderObj) {
		$orderObj = new ome_rpc_response_order ();
		$response = kernel::single ( 'base_rpc_service' );
	}
	
	base_rpc_service::$node_id = $nodeId;
	
	return $orderObj->add ( $sdf, $response );
}

function getShopList() {
	
	$db = kernel::database ();
	$list = $db->select ( "SELECT * FROM sdb_ome_shop WHERE shop_type='taobao' and disabled='false'" );
	if ($list) {
		foreach ( $list as $key => $item ) {
			
			$list [$key] ['addon'] = unserialize ( $item ['addon'] );
			$list [$key] ['config'] = unserialize ( $item ['config'] );
		}
		return $list;
	} else {
		
		return array ();
	}
}